{extend name="layout" /}
{block name="content"}
<!-- Content Header (Page header) -->
<section class="content" style="padding-top:0;padding-bottom: 0">
  <div class="row" style="padding-bottom: 0">
    <div class="box" style="margin-bottom: 0">
      <div class="box-header with-border">
        <h3 class="box-title"><i class="fa fa-building-o"></i> 消息管理</h3>
      </div>
      <!-- /.box-header -->
      <div class="box-body">
        <div class="row">
          <div class="col-xs-6">
            <form id="searchForm">
              <div class="seardiv" style="width: 20%;float: left;">
                <select name="tagid" class="form-control input-sm">
                  <option value="">请选择标签</option>
                  {volist name="taglist" id="v"}
                  <option value="{$key}">{$v}</option>
                  {/volist}
                </select>
              </div>
              {if condition="$uinfo['roleid'] == 1 || $uinfo['roleid'] == 4"}
              <div class="seardiv" style="width: 20%;float: left;">
                <select name="senduserid" class="form-control input-sm">
                  <option value="">请选择发布用户</option>
                  {volist name="senduserlist" id="v"}
                  <option value="{$key}">{$v}</option>
                  {/volist}
                </select>
              </div>
              {/if}
              <div class="input-group input-group-sm demoTable">
                <input type="text" class="form-control input-sm" name="keywords" id="demoReload" autocomplete="off"
                  placeholder="请输入标题或内容关键字">
                <!-- <span class="input-group-btn">
                  <button type="button" class="btn btn-info btn-flat searchBtn" pageid="pages" data-type="reload">搜 索</button> -->
                  <!-- <button type="button" class="btn btn-danger btn-flat cocoModal" isForm url="{:url('search')}">高级搜索</button> -->
                <!-- </span> -->
                <span class="input-group-btn">
                  <button type="button" class="btn btn-info btn-flat layui-btn" data-type="reload">搜 索</button>
                  </span>
              </div>
              <input type="hidden" name="fieldset" value="keywords-title|content-like">
            </form>
          </div>
          <div class="col-xs-6" style="text-align: right">
            <button type="button" class="btn btn-success btn-sm cocoModal" isForm url="{:url('add')}" title="新增项目" fixat="1"><i class="fa fa-plus"></i> 新增</button>
            <!-- <button type="button" class="btn btn-info btn-sm cocoModal" checkItem="1:1" isForm url="{:url('edit',array('model'=>$model))}"><i class="fa fa-edit"></i> 编辑</button> -->
            <!-- <button type="button" class="btn btn-danger btn-sm cocoAjax" confirm="确定要删除吗？" checkItem="1:0" ajaxUrl="{:url('data_delete',array('model'=>$model))}"><i class="fa fa-remove"></i> 删除</button> -->
            <!-- <button type="button" class="btn btn-info btn-sm cocoAjax" confirm="确定要发送吗？" checkItem="1:0" ajaxUrl="{:url('send_sysmsg',array('model'=>$model))}"><i class="fa fa-send"></i> 发送</button> -->
          </div>
        </div>
        <table class="layui-table" lay-even
          lay-data="{height: 'full-75', cellMinWidth: 80, page: true, id:'lists',limit:30, url:'{:url('get_message_list',['order'=>'desc'])}'}"
          lay-filter="lists">
          <colgroup>
            <col width="35">
            <col width="30">
          </colgroup>
          <thead>
            <tr>
              <th lay-data="{type:'checkbox'}">ID</th>
              <th lay-data="{field:'id', sort: true}">ID</th>
              <th lay-data="{field:'tagname'}">所属标签</th>
              <th lay-data="{field:'title'}">标题</th>
              <th lay-data="{field:'content'}">内容</th>
              <th lay-data="{field:'status'}">显示状态</th>
              <th lay-data="{field:'addtime'}">添加时间</th>
              <th lay-data="{field:'send_realname'}">发布用户</th>
              <th lay-data="{fixed:'right', width:180, align:'center', toolbar: '#barDemo'}">操作</th>
            </tr>
          </thead>
          <tbody id="datalist">
          </tbody>
        </table>
      </div>
      <!-- /.box-body -->
      <div id="pages" class="box-footer clearfix pages" style="text-align: center;padding:0"></div>
    </div>
  </div>
</section>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit_message">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- /.content -->
{/block}
{block name="script"}
<script type="text/javascript">
  layui.use('table', function () {
    var table = layui.table;
    var $ = layui.$, active = {
      reload: function () {
        var demoReload = $('#demoReload');
        //执行重载
        table.reload('lists', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          , where: $('#searchForm').serializeObject()
        });
      }
    };
    
    $('.demoTable .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  function edit_message(data) {
    console.dir(data);
    var layindex = layer.open({
      type: 2,
      area: ['800px', '600px'],
      fixed: false, //不固定
      maxmin: true,
      content: APP_URL + "/admin/message/edit?items=" + data.messageid,
      title: '修改消息内容',
      btn: ['确定', '取消'],
      shade: [0.8, '#000000'],
      yes: function (index, layero) {
        //parent.$('#parentIframe').text('我被改变了');
        var iframeWin = window[layero.find('iframe')[0]['name']];
        formobj = iframeWin.$("form");
        ajaxUrl = formobj.attr("action");
        if (ajaxUrl == undefined || ajaxUrl == '') {
          ajaxUrl = defaultSaveUrl;
        }
        datajson = formobj.serialize();
        searchMap.postData = datajson;
        $.post(ajaxUrl, searchMap, function (datajson) {
          var serializeObj = {};
          if (datajson.status == 1) {
            $(formobj.serializeArray()).each(function () {
              serializeObj[this.name] = this.value;
            });
            layer.msg("操作成功", function () {
              layer.closeAll();
            });
            setTimeout(function () {
              location.reload();
            }, 300);
          }
          else {
            layer.msg(datajson.msg);
            return false;
          }
        }, 'json');
      }
    });
  }
</script>
{/block}